package com.kaishu.misp.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishu.misp.dao.HibernateDao;
import com.kaishu.misp.service.GenericService;

@Service
public abstract class GenericServiceImpl<T> implements GenericService<T>{
	
	public abstract HibernateDao<T> getEntityDao();

	@Override
	@Transactional(readOnly = false)
	public void save(final T entity) {
		getEntityDao().save(entity);
	}

	@Override
	@Transactional(readOnly = false)
	public void update(T entity) {
		getEntityDao().update(entity);
	}

	@Override
	@Transactional(readOnly = false)
	public void delete(Serializable id) {
		getEntityDao().deleteById(id);
	}

	@Override
	@Transactional(readOnly = true)
	public int getTotal() {
		return getEntityDao().countAll();
	}

	@Override
	@Transactional(readOnly = true)
	public List<T> findAll(int page, int rows, String sort, String order) {
		return getEntityDao().findAll(page, rows, sort, order);
	}

	@Override
	@Transactional(readOnly = true)
	public boolean isExist(String propertyName, Object value) {
		return getEntityDao().isExist(propertyName, value);
	}
	
}
